package util;

import java.io.*;
import java.util.Date;

/**
 * User: Алексей
 * Date: 21.11.12
 * Time: 14:08
 */
public class Logger {

    public final static String INFO = "INFO";
    public final static String DEBUG = "DEBUG";
    public final static String ERROR = "ERROR";
    private static PrintWriter out;
    private static Logger logger = new Logger();

    static {
        /*try {
            out = new PrintWriter(new FileWriter("log.txt"), true);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }*/
    }

    public static Logger getLogger(){
        return logger;
    }

    public void info(String message){
        try {
            out = new PrintWriter(new FileWriter("log.txt"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        out.write(String.format("Date: %td/%<tm/%<tY %<tH:%<tM %s: %s\n", new Date(), INFO, message));
        //out.flush();
    }

    public void debug(String message){
        out.print(String.format("Date: %td/%<tm/%<tY %<tH:%<tM %s: %s\n", new Date(), DEBUG, message));
        //out.flush();
    }

    public void error(Exception e){
        out.write(String.format("Date: %td/%<tm/%<tY %<tH:%<tM %s: %s\n", new Date(), ERROR, e.getStackTrace()));
        //out.flush();
    }
}
